home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
PROGRAMM
/
DB_CLIPP
/
2510.ZIP
/
TRSOURCE.EXE
/
REG.ASM
< prev
next >
Wrap
Assembly Source File
|
1990-10-22
|
7KB
|
216 lines
; REG.ASM
;
; by Ralph Davis
; modified by Rick Spence
;
; Placed in the public domain by Tom Rettig Associates, 10/22/1990.
;
; SYNTAX: REG( <register name> )
;
; PARAMETERS: <expC> = name of register in upper-case or lower-case
;
; Valid registers are:
;
; AX, BX, CX, DX, SP, BP, SI, DI, DS, ES, SS, CS, IP,
; FF(Flags)
;
; RETURNS: Current contents of specified register as hexadecimal
; string.
;
PUBLIC REG
INCLUDE EXTENDA.MAC
EXTRN __TR_REG:FAR ; C function which converts
; register character string
; to number
; See EQUates below
EXTRN __TR_HEXASM:FAR
; Equates
; These EQUates correspond to the codes set up in _tr_reg()
REG_AX EQU 0
REG_BX EQU 1
REG_CX EQU 2
REG_DX EQU 3
REG_SP EQU 4
REG_BP EQU 5
REG_SI EQU 6
REG_DI EQU 7
REG_DS EQU 8
REG_ES EQU 9
REG_SS EQU 10
REG_CS EQU 11
REG_IP EQU 12
REG_FF EQU 13
DGROUP GROUP _DATA
;********************************************
_DATA SEGMENT WORD PUBLIC 'DATA'
NULLSTR DB 0 ; For error return
_DATA ENDS
;********************************************
;********************************************
REG_TEXT SEGMENT BYTE PUBLIC 'CODE'
ASSUME CS:REG_TEXT,DS:_DATA
;--------------------------------------------
REG PROC FAR
PUSH BP ; Caller's BP is now at [SP]
MOV BP,SP ; Caller's SP is BP+2
PUSH AX ; Save everybody
PUSH BX
PUSH CX
PUSH DX
PUSH SI
PUSH DI
PUSH DS
PUSH ES
PUSH SS
PUSHF ; Save flags in case they're wanted.
; At this point, the stack looks like this:
;
; SP+ 0: Caller's flags
; + 2: Caller's SS
; + 4: Caller's ES
; + 6: Caller's DS
; + 8: Caller's DI
; +10: Caller's SI
; +12: Caller's DX
; +14: Caller's CX
; +16: Caller's BX
; +18: Caller's AX
; In addition:
;
; BP contains the caller's stack pointer minus 2.
;
; BP+0: Caller's BP
; BP+2: Caller's IP
; BP+4: Caller's CS
; BP+6: Pointer to desired register
;
GET_CHAR 1 ; Get pointer to register string
PUSH DX ; and pass it to _tr_reg()
PUSH AX
CALL __TR_REG ; Convert it to a number
; Returns integer in AX
ADD SP,4
PUSH SS ; Use DS and BX to address
POP DS ; data saved on the stack
MOV BX,SP ;
CMP AX,REG_AX ; AX desired?
JNE REG1
MOV AX,[BX+18] ; Yes, pick it up
JMP REG20 ; and get out
REG1:
CMP AX,REG_BX ; BX desired?
JNE REG2
MOV AX,[BX+16] ; Yes
JMP REG20
REG2:
CMP AX,REG_CX ; CX desired?
JNE REG3
MOV AX,[BX+14] ; Yes
JMP REG20
REG3:
CMP AX,REG_DX ; DX desired?
JNE REG4
MOV AX,[BX+12] ; Yes
JMP REG20
REG4:
CMP AX,REG_SP ; SP desired?
JNE REG5
MOV AX,BP ; Yes
ADD AX,2 ; Old SP = Current BP + 2
JMP REG20
REG5:
CMP AX,REG_BP ; BP desired?
JNE REG6
MOV AX,[BP] ; Yes
JMP REG20
REG6:
CMP AX,REG_SI ; SI desired?
JNE REG7
MOV AX,[BX+10] ; Yes
JMP REG20
REG7:
CMP AX,REG_DI ; DI desired?
JNE REG8
MOV AX,[BX+8] ; Yes
JMP REG20
REG8:
CMP AX,REG_DS ; DS desired?
JNE REG9
MOV AX,[BX+6] ; Yes
JMP REG20
REG9:
CMP AX,REG_ES ; ES desired?
JNE REG10
MOV AX,[BX+4] ; Yes
JMP REG20
REG10:
CMP AX,REG_SS ; SS desired?
JNE REG11
MOV AX,[BX+2] ; Yes
JMP REG20
REG11:
CMP AX,REG_CS ; CS desired?
JNE REG12
MOV AX,[BP+4] ; Yes
JMP REG20
REG12:
CMP AX,REG_IP ; IP desired?
JNE REG13
MOV AX,[BP+2] ; Yes
JMP REG20
REG13:
CMP AX,REG_FF ; Flags desired?
JNE REG14
MOV AX,[BX] ; Yes
JMP REG20
REG14:
MOV DX,_DATA ; Return null string
MOV AX,OFFSET NULLSTR ; for invalid register
JMP EXIT
REG20:
; At this point, AX contains return value
;
; Call _TR_HEXASM to convert it to a hexadecimal string
XOR BX,BX ; Push a word of zeroes
PUSH BX ; so _TR_HEXASM will know we only
; want a 4-digit string
PUSH AX
CALL __TR_HEXASM ; DX:AX now contains pointer
; to return string
ADD SP,4
EXIT:
POPF ; Restore caller's flags and registers
POP SS
POP ES
POP DS
POP DI
POP SI
ADD SP,2
POP CX
POP BX
ADD SP,2 ; Discard saved values
; of DX and AX
POP BP
RET_CHAR DX,AX ; Return char * to caller
RET
REG ENDP
;-------------------------------------------
REG_TEXT ENDS
;*******************************************
END